//
//  MyImageView.m
//  iphoneApp
//
//  Created by Liyu on 12-11-11.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "MyImageView.h"
#import <QuartzCore/QuartzCore.h>

#define TweenValue 10.0/10.0
@implementation MyImageView
{

    CGFloat initCenterX;
}

@synthesize time=_time;
@synthesize delegate;

-(id) init
{
    self=[super init];
    if (self) {
        self.userInteractionEnabled=YES;
    }
    return self;
}


- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
    }
    return self;
}

-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    
    NSTimer * time1=[NSTimer scheduledTimerWithTimeInterval:0.01 target:self
                                                   selector:@selector(inCreaseSize:) userInfo:nil repeats:YES];
    self.time=time1;
}


-(void) inCreaseSize:(id *) sender
{
    CGFloat w=self.frame.size.width;
    CGFloat h=self.frame.size.height;
    CGFloat num=(320-4*2.0)/3.0+10.0;
    
    if (w>=num) {
        
        [self.time invalidate];
        self.time=nil;
        self.time=[NSTimer  scheduledTimerWithTimeInterval:0.01 target:self
                                                  selector:@selector(reduceSize:) userInfo:nil repeats:YES];
        return;
    }   
   self.frame=CGRectMake(self.frame.origin.x-TweenValue/2.0, self.frame.origin.y-TweenValue/2.0, w+TweenValue, h+TweenValue);
}

-(void) reduceSize:(id *) sender
{
    CGFloat w=self.frame.size.width;
    CGFloat h=self.frame.size.height;
    CGFloat num=(320-4*2.0)/3.0;
    
    if (w<=num) {
        
        [self.time invalidate];
        self.time=nil;
        self.layer.borderWidth=0;
        [self.delegate MyImageViewTap:self];
    }   
    self.frame=CGRectMake(self.frame.origin.x+TweenValue/2.0, self.frame.origin.y+TweenValue/2.0, w-TweenValue, h-TweenValue);
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

@end
